from langchain.agents import initialize_agent
from langchain.chat_models import init_chat_model
from tool import detect_defect_tool,summarize_defects_tool

api_key = "sk-629f3f032ce248e090f62edf4cace885"

model = init_chat_model(
    "qwen-turbo",
    model_provider="openai",
    api_key=api_key,  # 直接传顶层 api_key
    openai_api_base="https://dashscope.aliyuncs.com/compatible-mode/v1",  # 阿里云服务地址
)

#初始化agent
agent = initialize_agent( #组合 LLM + 工具，快速生成一个 Agent
    tools=[detect_defect_tool, summarize_defects_tool], #传入工具列表
    llm=model,
    agent="zero-shot-react-description", #指定agent类型
    verbose = True
)

response = agent.run("请帮我分析一下D:/lab/detect/crazing_2.jpg的缺陷 并分析一下")
print(response)
